﻿/*----------------------------------------------------------------
// 公司名称：公司名称
// 
// 产品名称：Gaf
//
// 创 建 人：netcasewqs
// 创建日期：2022/3/4
// 邮    箱：netcasewqs@qq.com
//
// Copyright (C) 2022 Gaf，保留所有权利。
//
//----------------------------------------------------------------*/

namespace Gaf;

/// <summary>
/// Framework接口
/// </summary>
public interface IGaf
{
    /// <summary>
    /// Gaf框架配置信息
    /// </summary>
    GafOptions Options { get; }

    /// <summary>
    /// 插件管理器
    /// </summary>
    IAddinManager AddinManager { get; }

    /// <summary>
    /// 框架状态
    /// </summary>
    FrameworkState State { get; }

    /// <summary>
    /// 获取插件路径（通过插件名称)
    /// </summary>
    /// <param name="addinName"></param>
    /// <returns></returns>
    public string? GetAddinLocation(string addinName)
    {
        var addin = AddinManager.Addins.FirstOrDefault(x => x.Name.ToLower().Trim() == addinName.ToLower().Trim());
        return addin?.Location;
    }

    /// <summary>
    /// 
    /// </summary>
    public string? GetAddinLocation(Assembly asm)
    {
        var addin = AddinManager.Addins.FirstOrDefault(x => x.Assemblies.Any(p => p == asm));
        return addin?.Location;
    }

    /// <summary>
    /// 插件状态改变事件
    /// </summary>
    event Action<IAddin> AddinStateChanged;

    /// <summary>
    /// 框架状态改变事件
    /// </summary>
    event Action<IGaf> FramewormStateChanged;

    /// <summary>
    /// 框架异常
    /// </summary>
    event Action<IGaf,Exception> FrameworkErrorOccurred;

    /// <summary>
    /// 
    /// </summary>
    void Configure(IServiceCollection? services = null, IConfiguration? configuration = null);
    /// <summary>
    /// 启动Framework
    /// </summary>
    void Start(IServiceProvider provider);

    /// <summary>
    /// 
    /// </summary>
    void Shutdown();

}
